package com.pojo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Player {
    /**
     * 水（箱）
     */
    private Integer waterNum;
    /**
     * 食物（箱）
     */
    private Integer foodNum;
    /**
     * 资金（元）
     */
    private Integer capital;
    /**
     * 当前日期
     */
    private Integer nowDate;
    /**
     * 位置点
     */
    private GameMap mapId;
    /**
     * 水总消耗
     */
    private Integer waterEat;
    /**
     * 食物总消耗
     */
    private Integer foodEat;

    public static enum resourcesType {
        /**
         * 晴朗
         */
        sunny,
        /**
         * 高温
         */
        high,
        /**
         * 沙暴
         */
        Sandstorm
    }

    public Player(Integer waterNum, Integer foodNum, Integer capital, Integer nowDate, GameMap mapId,Integer waterEat,Integer foodEat) {
        this.waterNum = waterNum;
        this.foodNum = foodNum;
        this.capital = capital;
        this.nowDate = nowDate;
        this.mapId = mapId;
        this.waterEat = waterEat;
        this.foodEat = foodEat;
    }

    public Player(Integer waterNum, Integer foodNum, Integer capital, GameMap mapId) {
        this.waterNum = waterNum;
        this.foodNum = foodNum;
        this.capital = capital;
        this.mapId = mapId;
    }

    public Integer getWaterNum() {
        return waterNum;
    }

    public void setWaterNum(Integer waterNum) {
        this.waterNum = waterNum;
    }

    public Integer getFoodNum() {
        return foodNum;
    }

    public void setFoodNum(Integer foodNum) {
        this.foodNum = foodNum;
    }

    public Integer getCapital() {
        return capital;
    }

    public void setCapital(Integer capital) {
        this.capital = capital;
    }


    public Integer getNowDate() {
        return nowDate;
    }

    public void setNowDate(Integer nowDate) {
        this.nowDate = nowDate;
    }

    public GameMap getMapId() {
        return mapId;
    }

    public void setMapId(GameMap mapId) {
        this.mapId = mapId;
    }

    public Integer getWaterEat() {
        return waterEat;
    }

    public void setWaterEat(Integer waterEat) {
        this.waterEat = waterEat;
    }

    public Integer getFoodEat() {
        return foodEat;
    }

    public void setFoodEat(Integer foodEat) {
        this.foodEat = foodEat;
    }

    public void printPlayer(){
        System.out.printf("\t%-13s\t%-13s\t%-13s\t%-13s\n","所在区域=" + mapId.getId(),"剩余资金=" + capital,"剩余水量=" + waterNum,"剩余食物=" + foodNum);
    }

    public static List<resourcesType> resourcesList(int sunny,int high,int sandstorm,int dayNum,int seed){
        ArrayList<resourcesType> resourcesTypeArrayList = new ArrayList<resourcesType>();
        Random r = new Random(seed);
        int n = sunny + high + sandstorm;
        for (int i=0;i<dayNum;i++){
            int random = r.nextInt(n);
            if (random<=sunny){
                resourcesTypeArrayList.add(resourcesType.sunny);
            }else if (random<=sunny+high){
                resourcesTypeArrayList.add(resourcesType.high);
            }else{
                resourcesTypeArrayList.add(resourcesType.Sandstorm);
            }
        }
        return resourcesTypeArrayList;
    }

    @Override
    public String toString() {
              return  "\t所在区域:" + mapId.getId() +
                "\t剩余资金:" + capital +
                "\t剩余水量:" + waterNum +
                "\t剩余食物:" + foodNum;
    }
}
